﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Chefbook.DataObjects;
using NUnit.Framework;
using Chefbook.DataObjects.XmlSerialization;

namespace UnitTests.DataObjectsTests.XmlSerializationTests
{
    public class RecipeXmlSerializationFixture
    {
        private XDocument doc;
        private List<Recipe> recipes;

        [SetUp]
        public void Init()
        {
            doc = XDocument.Load("RecipeSerialized.xml");
            recipes = new List<Recipe>();

            Category root = new Category(null) { Name = "Root" };
            Recipe chickenShrimpScampi = new Recipe(root)
            {
                Name = "Chicken and Shrimp Scampi",
                Description = "A delicious combination of shrimp and chicken",
                Directions = "Take some chicken, and shrimp and cut them up and cook",
                CookTime = TimeSpan.FromMinutes(30),
                PrepTime = TimeSpan.FromMinutes(45)
            };
            Ingredient chicken = new Ingredient(chickenShrimpScampi)
            {
                Name = "Chicken breasts, sliced",
                Amount = 1,
                Units = "Lbs"
            };
            Ingredient shrimp = new Ingredient(chickenShrimpScampi)
            {
                Name = "Jumbo Shrimp",
                Amount = 10,
                Units = string.Empty
            };
            Ingredient butter = new Ingredient(chickenShrimpScampi)
            {
                Name = "Salted Butter",
                Amount = 3,
                Units = "tbsp"
            };

            Recipe chickenFettuciniAlfredo = new Recipe(root)
            {
                Name = "Chicken Fettuccini Alfredo",
                Description = "A creamy chicken alfredo",
                Directions = "Boil up the pasta",
                CookTime = TimeSpan.FromMinutes(75),
                PrepTime = TimeSpan.FromMinutes(25)
            };
            Ingredient chicken2 = new Ingredient(chickenFettuciniAlfredo)
            {
                Name = "Chicken breasts, sliced",
                Amount = 1,
                Units = "Lbs"
            };
            Ingredient Fettuccini = new Ingredient(chickenFettuciniAlfredo)
            {
                Name = "Fettuccini",
                Amount = 1,
                Units ="Box"
            };
            Ingredient AlfredoSauce = new Ingredient(chickenFettuciniAlfredo)
            {
                Name = "Alfredo Sauce",
                Amount = 2,
                Units = "Jars"
            };
            recipes.Add(chickenShrimpScampi);
            recipes.Add(chickenFettuciniAlfredo);
        }

        [Test]
        public void TestReadingCategoryXml()
        {
            var expected = recipes.ToList();
            var actual = RecipeXmlSerializer.DeserializeRecipes(doc).ToList();
            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.True(expected[i].ValueEquals(actual[i]));
            }
        }

        [Test]
        public void TestWritingCategoryXml()
        {

            XDocument actual = RecipeXmlSerializer.SerializeRecipes(recipes);
            Assert.AreEqual(doc.ToString(), actual.ToString());
        }


    }
}
